<template>
  <view>
    <view class="my-search-box">
      <my-search @click.native="gotoSearch"></my-search>
    </view>
    
<!--  轮播图 -->
    <swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
      <swiper-item v-for="(item,i) in swiperList" :key="i">
        <navigator class="swiper-item" :url="'/subpkg/goods_list/goods_list?goods_id='+item.goods_id">
          <image :src="item.image_src"></image> 
       </navigator>
      </swiper-item>
    </swiper>
 <!-- 分类 -->
<view class="castList">
    <view class="cast-item" v-for="(item,i) in cateList" :key="i" @click="castClick(item)">
      <image :src="item.image_src" ></image>
    </view>
  </view>
  <!-- 楼层展示 -->
  <view class="FloorList" v-for="(item,i) in floorList" :key="i">
   <view class="FloorTitle">
     <image :src="item.floor_title.image_src" ></image>
   </view>
   <view class="FloorContent">
     <view class="floorLeft" >
          <image :src="item.product_list[0].image_src"  :style="{width: item.product_list[0].image_width+'rpx'}" mode="widthFix" :url="item.product_list[0].url"></image>
      </view>
      <view class="floorRight">
        <navigator class="floorItem" v-for="(fI,i) in item.product_list.filter((item,i1)=>i1!==0 )" :key="i" :url="fI.url">
            <image :src="fI.image_src" :style="{width: fI.image_width+'rpx'}" mode="widthFix"></image>
        </navigator>
      </view>
   </view>
      
     
  </view>
  </view>
  </view>
</template>

<script>
 // 导入自己封装的 mixin 模块
 import badgeMix from '@/mixins/tabbar-badge.js'
 
 export default {
   // 将 badgeMix 混入到当前的页面中进行使用
   mixins: [badgeMix],
    data() {
      return {
        // 轮播图列表
        swiperList: [],
        //分类列表
        cateList:[],
        //楼层数据
        floorList:[]
      };
    },
    // computed:{
    //   ...mapGetters('m_cart',['total'])
    // },
    onLoad() {
      this.getSwipeList()
      this.getCateList()
      this.getFloorList()
    },

    methods: {
      //去搜索页
      gotoSearch(){
        uni.navigateTo({
          url:'/subpkg/search/search'
        })
      },
      // 获取轮播图
      async getSwipeList() {
        const {data: res} = await uni.$http.get('home/swiperdata')
        if (res.meta.status !== 200)  return uni.$showMsg
        this.swiperList = res.message
        uni.$showMsg('数据请求成功')
      },
      // 获取分类
      async getCateList(){
        const {data:res}=await uni.$http.get('home/catitems')
        console.log(res);
        if (res.meta.status !== 200)  return uni.$showMsg
        this.cateList=res.message
      },
        //点击分类触发事件
        castClick(item){
            console.log(item);
            if(item.name==='分类'){
              uni.switchTab({
                url:'/pages/cate/cate'
              })
            }
        },
      //获取楼层
     async getFloorList(){
        const {data:res}=await uni.$http.get('home/floordata')
        console.log(res);
        res.message.forEach(floor=>{
          floor.product_list.forEach(prod=>{
            prod.url='/subpkg/goods_list/goods_list?'+prod.navigator_url.split('?')[1]
          })
        })
        this.floorList=res.message
      }
    }
  }
</script>

<style lang="scss" scoped>
  .my-search-box{
    position: sticky;
    top: 0;
    z-index: 999;
  }
  swiper {

    height: 330rpx;
    .swiper-item,
    image {
      width: 100%;
       height: 100%
    }
  }
.castList{
  margin-top: 30rpx;
  height: 130rpx;
  display: flex;
  justify-content: space-around;
    
  .cast-item{
   width: 100%;
   display: flex;
   flex-direction: column;
   justify-content: center;
   align-items: center;
    image{
      width: 120rpx;
      height: 120rpx;
    }
   
  }
}
.FloorList{
  margin-top: 50rpx;
  // height: 400rpx;
  .FloorTitle,image{
    height: 50rpx;
  }
  .FloorContent{
    display: flex;
    .floorRight{
      display: flex;
      flex-wrap: wrap;
      justify-content: space-around;
    }
  }
  }
 

</style>
